package com.transfiguro.datamodel.csmodels;

import com.transfiguro.datamodel.GenericStatement;
import com.transfiguro.datamodel.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CSForEachStatement extends GenericStatement {
    private final Logger logger = LoggerFactory.getLogger(CSForEachStatement.class);
    private CSVariable variable;
    private CSVariable iterator;
    private String loopBody;
    private static final String STATEMENT = "foreach";

    public CSVariable getVariable() {
        return variable;
    }

    public void setVariable(final CSVariable variable) {
        this.variable = variable;
    }

    public CSVariable getIterator() {
        return iterator;
    }

    public void setIterator(final CSVariable iterator) {
        this.iterator = iterator;
    }

    public String getLoopBody() {
        return loopBody;
    }

    public void setLoopBody(final String loopBody) {
        this.loopBody = loopBody;
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append('\n');
        result.append(STATEMENT).append('(').append(variable != null ? variable : "Iterator Not Found")
                .append(" in ")
                .append(iterator != null ? iterator : "Variable Not Found")
                .append(") {\n");
        if (statements != null) {
            for (final Statement statement : statements) {
                result.append(statement.toString());
            }
        } else {
            result.append("//This loop does not have a body");
        }
        result.append("\n}");
        result.append('\n');
        return result.toString();
    }
}
